//
//  NYTabBarController.m
//  百思不得姐
//
//  Created by Apple on 15/8/21.
//  Copyright (c) 2015年 Neal. All rights reserved.
//

#import "NYTabBarController.h"
#import "NYEssenceViewController.h"
#import "NYNewViewController.h"
#import "NYFriendTrendsViewController.h"
#import "NYMeViewController.h"
#import "NYTabBar.h"
#import "NYNavigationController.h"

@interface NYTabBarController ()

@end

@implementation NYTabBarController

//设置 tabbar 的文字属性
+ (void)initialize{
    
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selattrs = [NSMutableDictionary dictionary];
    selattrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:selattrs forState:UIControlStateSelected];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setChildrenVC];
    
    [self setupTabBar];
    
}
//自定义 tabbar
- (void)setupTabBar{
    [self setValue:[[NYTabBar alloc]init] forKeyPath:@"tabBar"];
}
// 设置子控制器
- (void)setChildrenVC{
    
    NYFriendTrendsViewController *friend = [[NYFriendTrendsViewController alloc]init];
    [self setOnechildVC:friend title:@"关注" image:[UIImage imageNamed:@"tabBar_friendTrends_icon"] selectedImage:[UIImage imageNamed:@"tabBar_friendTrends_click_icon"]];
    
    NYEssenceViewController *essence = [[NYEssenceViewController alloc]init];
    [self setOnechildVC:essence title:@"精华" image:[UIImage imageNamed:@"tabBar_essence_icon"] selectedImage:[UIImage imageNamed:@"tabBar_essence_click_icon"]];
    
    NYNewViewController  *new = [[NYNewViewController alloc]init];
    [self setOnechildVC:new title:@"新帖" image:[UIImage imageNamed:@"tabBar_new_icon"] selectedImage:[UIImage imageNamed:@"tabBar_new_click_icon"]];
    


    NYMeViewController *me = [[NYMeViewController alloc]initWithStyle:UITableViewStyleGrouped];
    [self setOnechildVC:me title:@"我的" image:[UIImage imageNamed:@"tabBar_me_icon"] selectedImage:[UIImage imageNamed:@"tabBar_me_click_icon"]];
    
}

- (void)setOnechildVC:(UIViewController *)vc title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectimage{
    
    vc.title = title;
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = [selectimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NYNavigationController *nav = [[NYNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

@end
